home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / dtr / openpane.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  7.2 KB  |  225 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /*$Header: /Source/Media/collab/DTR/RCS/openpanel.c,v 2.0 92/01/06 17:58:08 drapeau Exp Locker: derek $*/
  25. /* $Log:    openpanel.c,v $
  26.  * Revision 2.0  92/01/06  17:58:08  drapeau
  27.  * Modified both OpenHandler() and SaveHandler() to reflect the newly-integrated
  28.  * ReadSoundFile() function.
  29.  * Also, Made a number of cosmetic changes to make code easier to read and
  30.  * to conform to programming specifications.
  31.  * 
  32.  * Revision 1.9  91/10/09  17:22:02  derek
  33.  * Save Edit List bug fixed.
  34.  * 
  35.  * Revision 1.8  91/09/18  22:47:31  derek
  36.  * The following things are done:
  37.  * 1.    The Makefile is changed corresponding to the changes in collab/.
  38.  * 2.    Copyright messages included.
  39.  * 3.    Some minor bugs fixed.
  40.  * 
  41.  * Revision 1.7  91/08/22  15:48:52  derek
  42.  * The format of the DTR edit-list has been changed.  The header is 
  43.  * changed from "#DTR Edit File#" to "#DTR Edit Document#".  Also,
  44.  * EditNumber is added to every edit within the edit-list.
  45.  * 
  46.  * Revision 1.6  91/08/21  11:34:23  derek
  47.  * The following changes are made:
  48.  * 1.    Now the duration and size of the recorded sound will be displayed
  49.  *     during recording.
  50.  * 2.    I have changed GetSelection() corresponding to the request of Tek joo
  51.  * 3.    Info Panel is added to the application.
  52.  * 4.    Fixed SizeToFitHandler() so that when no file or buffer is currently
  53.  *     loaded, it would not do anything (except giving a warning
  54.  *     notice_prompt).
  55.  * 5.    Inplemented the `Close' Menu option in the document menu.
  56.  * 6.    Fixed the bug in which after ClearAll and I press PreviewEdit,
  57.  *     the edit wont be played.
  58.  * 7.    I have made the changes corresponding to the change in OpenPanel's
  59.  *     name.  (from OpenPanel to Browse).
  60.  * 8.    Incorporated BrowseCheck to check command line arg.
  61.  * 9.    Changed most EditingStatusMessages to NoticePrompts.
  62.  * 10.    SoundFileSaveAsPopUp and EditListSaveAsPopUp are removed 
  63.  *     from the application.
  64.  * 
  65.  * Revision 1.5  91/08/16  18:10:44  derek
  66.  * 
  67.  * The following things are done:
  68.  * 1.    I have fixed an openpanel bug in my code in which I 
  69.  *     made the app return the wrong values to OpenHandler and
  70.  *     the SaveHandler.
  71.  * 2.    The flashing color of the play button has been changed from
  72.  *     Red to Green.
  73.  * 3.    Fixed a quantization bug: Buffer.play.end, when converted
  74.  *     from endingTimeInSec, should not exceed Buffer_hdr_data_size - 1.
  75.  * 
  76.  * Revision 1.4  91/08/14  16:14:07  derek
  77.  * Fixed a few saving/appending bugs.
  78.  * 
  79.  * Revision 1.3  91/08/08  21:44:43  derek
  80.  * Fixed a number of bugs.
  81.  * 
  82.  * Revision 1.2  91/08/07  16:24:32  derek
  83.  * The Edit list part of DTR is done.  OpenPanel is also incorporated.
  84.  * 
  85.  * Revision 1.1  91/08/06  12:41:49  derek
  86.  * Initial revision
  87.  *  */
  88. static char rcsid[] = "$Header: /Source/Media/collab/DTR/RCS/openpanel.c,v 2.0 92/01/06 17:58:08 drapeau Exp Locker: derek $";
  89.  
  90. #include "dtr.h"
  91. #include "dtr_ui.h"
  92.  
  93. extern  dtr_mainWindow_objects *dtr_mainWindow;
  94.  
  95. void
  96.   InitOpenPanel()
  97. {
  98.   (void) CreateBrowse(OpenHandler,
  99.               SaveHandler,
  100.               dtr_mainWindow->mainWindow);
  101.   documentFirstLine = (char *)strdup("#DTR Edit Document#");
  102.   documentFileType = (char *)strdup("DTR");
  103. }
  104.  
  105.  
  106. /*
  107.  *  This OpenHandler is called by Browse(), which in turn is invoked by
  108.  *  Menu_item Open(item, op).
  109.  */
  110. int
  111.   OpenHandler(proposedPath, id)
  112. char  *proposedPath;
  113. int   id;
  114. {
  115.   int    status;
  116.  
  117.   status = FILE_NOT_OK;
  118.   switch(id)
  119.   {
  120.    case IS_SOUNDFILE:
  121.     sprintf(currentSoundFile,"%s",proposedPath);
  122.     UpdateHeader(FALSE);
  123.     if (WaveEditMode == FALSE)
  124.     {
  125.       FileReady = ReadSoundFile(FALSE);
  126.       SoundBufferReady = FALSE;
  127.     }
  128.     else
  129.     {
  130.       SoundBufferReady = ReadSoundFile(TRUE);
  131.       FileReady = FALSE;
  132.     }
  133.     SameSoundFile = TRUE;
  134.     if ((FileReady == TRUE) || (SoundBufferReady == TRUE)) 
  135.     {
  136.       RepaintWaveCanvas();
  137.       RepaintGlobalWaveCanvas();
  138.       status = FILE_OK;
  139.     }
  140.     else
  141.     {
  142.       sprintf(currentSoundFile,"Untitled");
  143.       UpdateHeader(FALSE);
  144.     }
  145.  
  146.     break;
  147.     
  148.    case IS_EDITLIST:
  149.     status = ReadEditListFromFile(proposedPath, USER);
  150.     break;
  151.    
  152.    default:
  153.     fprintf(stderr, "Unknown id value in OpenHandler.\n");
  154.     status = FILE_NOT_OK;
  155.     break;
  156.   }
  157.   
  158.   return(status);
  159. }
  160.  
  161.  
  162. /*
  163.  *  This SaveHandler is called by Browse(), which in turn is invoked by
  164.  *  Menu_item Save(item, op).
  165.  */
  166. int
  167.   SaveHandler(proposedPath, id)
  168. char  *proposedPath;
  169. int   id;
  170. {
  171.   char        sourceFileName[80];
  172.   char        destFileName[80];
  173.   BOOL        append;
  174.   char        reply;
  175.   BOOL        exists;
  176.   struct stat    st;
  177.     
  178.   switch(id)
  179.   {
  180.    case IS_SOUNDFILE:
  181.     sprintf(currentSoundFile,"%s",proposedPath);
  182.     UpdateHeader(FALSE);
  183.     if ((WaveEditMode == TRUE) && (SoundBufferReady == FALSE))        /*  If in Edit mode and the sound buffer is not...  */
  184.     {                                    /*  ...ready, we need not save anything.            */
  185.       return FILE_NOT_OK;
  186.     }
  187.     strcpy(sourceFileName, Buffer.filename);
  188.     if (strcmp(sourceFileName, "\0") == 0)                /*  Here, currentSoundFile contains the...          */
  189.     {                                    /*  ...destFileName.  Buffer.filename contains...   */
  190.       AlertByNoticePrompt(dtr_mainWindow->menuControlPanel,        /*  ...sourceFileName.                              */
  191.               " Error --- No source sound available."); 
  192.       return FILE_NOT_OK;
  193.     }
  194.     exists = (stat(currentSoundFile, &st) == 0);
  195.     if (!exists)
  196.       append = FALSE;
  197.     else 
  198.     {
  199.       reply = notice_prompt(dtr_mainWindow->menuControlPanel, NULL, /*  destination file already exists.  Should ask... */
  200.                 NOTICE_MESSAGE_STRINGS,            /*  use if he really wants to append or overwrite.  */
  201.                 "File exists.  Append data to existing",
  202.                 "file or overwrite it?",
  203.                 NULL,
  204.                 NOTICE_BUTTON, "Append", 'A',
  205.                 NOTICE_BUTTON, "Overwrite", 'O',
  206.                 NOTICE_BUTTON, "Cancel", 'C',
  207.                 NULL);
  208.       if (reply == 'A')
  209.     append = TRUE;
  210.       else if (reply == 'O')
  211.     append = FALSE;
  212.       else return FILE_NOT_OK;
  213.     }
  214.     return(SaveSoundFile(append, sourceFileName, currentSoundFile));
  215.     break;
  216.    case IS_EDITLIST:
  217.     return(WriteEditListToFile(proposedPath));
  218.     break;
  219.    default:
  220.     fprintf(stderr, "Unknown id value in SaveHandler.\n");
  221.     break;
  222.   }                                    /* end switch(id) */
  223. }                                    /* end function SaveHandler */
  224.  
  225.